package com.kaifamiao.buffer;

/**
 * 1、有参构造:  StringBuffer( String srouce )
 * 2、char charAt(int index )
 * 3、void setCharAt( int offset, char ch )
 * 4、void setLength( int newLength )
 * 5、CharSequence subSequence( int start, int end )
 * 6、String substring( int start )
 * 7、String substring( int start , int end )
 * 8、void trimToSize()
 */
public class TestStringBuffer2 {

    public static void main(String[] args) {

        StringBuffer buffer = new StringBuffer( "开发喵" );
        System.out.println( "capacity: " + buffer.capacity() + ", length: " + buffer.length() );

        System.out.println( buffer.charAt( 1 ) );
        buffer.setCharAt( 1, '發' );
        System.out.println( buffer );

        buffer.setLength(0);
        System.out.println( "capacity: " + buffer.capacity() + ", length: " + buffer.length() );
        System.out.println( buffer );

        buffer.append( "云创动力·开发喵" );
        System.out.println( "capacity: " + buffer.capacity() + ", length: " + buffer.length() );
        System.out.println( buffer );

        CharSequence cs = buffer.subSequence( 0 , 4 );
        System.out.println( cs );

        String sub = buffer.substring( 2, 4 );
        System.out.println( sub );

        String str = buffer.substring( 5 );
        System.out.println( str );

        System.out.println( "capacity: " + buffer.capacity() + ", length: " + buffer.length() );
        buffer.trimToSize();
        System.out.println( "capacity: " + buffer.capacity() + ", length: " + buffer.length() );

    }

}
